package Q232

import java.util.*

class Main {

}

fun main(){

}

//两个栈实现队列
class MyQueue {

    var stackIn : Stack<Int> = Stack()
    var stackOut : Stack<Int> = Stack()

    fun push(x: Int) {
        stackIn.push(x)
    }

    fun pop(): Int {
        if(stackOut.isEmpty()){
            in2Out()
        }
        return stackOut.pop()
    }

    private fun in2Out() {
        while(!stackOut.isEmpty()){
            stackOut.push(stackIn.pop())
        }
    }

    fun peek(): Int {
        if(stackOut.isEmpty()){
            in2Out()
        }
        return stackOut.peek()!!
    }

    fun empty(): Boolean {
        return stackIn.isEmpty() && stackOut.isEmpty()
    }

}

